package com.finer.service.impl;

import com.finer.dao.FinerSaleBackRequestDetailDao;
import com.finer.entity.sell.FinerSaleBackRequestDetail;
import com.finer.service.FinerSaleBackRequestDetailService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 销售退货申请详情表(FinerSaleBackRequestDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:39
 */
@Service("finerSaleBackRequestDetailService")
public class FinerSaleBackRequestDetailServiceImpl implements FinerSaleBackRequestDetailService {
    @Resource
    private FinerSaleBackRequestDetailDao finerSaleBackRequestDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param Id 主键
     * @return 实例对象
     */
    @Override
    public FinerSaleBackRequestDetail queryById(Integer Id) {
        return this.finerSaleBackRequestDetailDao.queryById(Id);
    }

    /**
     * 分页查询
     *
     * @param finerSaleBackRequestDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerSaleBackRequestDetail> queryByPage(FinerSaleBackRequestDetail finerSaleBackRequestDetail, PageRequest pageRequest) {
        long total = this.finerSaleBackRequestDetailDao.count(finerSaleBackRequestDetail);
        return new PageImpl<>(this.finerSaleBackRequestDetailDao.queryAllByLimit(finerSaleBackRequestDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerSaleBackRequestDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleBackRequestDetail insert(FinerSaleBackRequestDetail finerSaleBackRequestDetail) {
        this.finerSaleBackRequestDetailDao.insert(finerSaleBackRequestDetail);
        return finerSaleBackRequestDetail;
    }

    /**
     * 修改数据
     *
     * @param finerSaleBackRequestDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleBackRequestDetail update(FinerSaleBackRequestDetail finerSaleBackRequestDetail) {
        this.finerSaleBackRequestDetailDao.update(finerSaleBackRequestDetail);
        return this.queryById(finerSaleBackRequestDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param Id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Id) {
        return this.finerSaleBackRequestDetailDao.deleteById(Id) > 0;
    }
}
